//
//  AKPMessageListCellButton.m
//  Copy_AiKapPu_Personal_OC
//
//  Created by taojianz on 2017/7/13.
//  Copyright © 2017年 taojianz. All rights reserved.
//

#import "AKPMessageListCellButton.h"

@implementation AKPMessageListCellButton


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]){
        [self setupUI];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(void)setupUI{
    
    // 关闭按钮的手势接收功能，让点击cell触发事件
    [self setUserInteractionEnabled:false];
    
    // 设置按钮高亮背景 , 裁剪按钮圆角
    UIImage *bgImage = [UIImage imageNamed:@"bigShadow"];
    [self setBackgroundImage:bgImage forState:UIControlStateHighlighted];
    self.clipsToBounds = true;
    
    CGFloat btnWidth = self.frame.size.width;
    
    _btnTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(3, 3, btnWidth, 30)];
    
    _btnTitleLabel.text = @"欢迎注册爱靠谱";
    _btnTitleLabel.font = [UIFont systemFontOfSize:15];
    
    _btnSubTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(3, 38, btnWidth, 25)];
    
    _btnSubTitleLabel.font = [UIFont systemFontOfSize:14];
    _btnSubTitleLabel.text = @"Welcome to AKP！";
    _btnSubTitleLabel.textColor = [UIColor lightGrayColor];
    
    _dottedLine = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"虚线"]];
    
    _seeDetail = [[UILabel alloc]init];
    _seeDetail.text = @"查看详情→";
    _seeDetail.font = [UIFont systemFontOfSize:14];
    _seeDetail.textColor = [UIColor darkGrayColor];
    
    
    [self addSubview:_btnTitleLabel];
    [self addSubview:_btnSubTitleLabel];
    [self addSubview:_seeDetail];
    [self addSubview:_dottedLine];
    
    self.layer.cornerRadius = 5;
    
    // 设置btnTitleLabel 约束
    
//    _btnTitleLabel.translatesAutoresizingMaskIntoConstraints = false;
    for (UIView *views in self.subviews) {
        views.translatesAutoresizingMaskIntoConstraints = false;
    }
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_btnTitleLabel
                                                    attribute:NSLayoutAttributeTop
                                                    relatedBy:NSLayoutRelationEqual
                                                       toItem:self
                                                    attribute:NSLayoutAttributeTop
                                                   multiplier:1
                                                     constant:8]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_btnTitleLabel
                                                     attribute:NSLayoutAttributeLeft
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:self
                                                     attribute:NSLayoutAttributeLeft
                                                    multiplier:1
                                                      constant:8]];
    
    // 设置btnSubLabel 约束
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_btnSubTitleLabel
                                                     attribute:NSLayoutAttributeTop
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:_btnTitleLabel
                                                     attribute:NSLayoutAttributeBottom
                                                    multiplier:1
                                                      constant:8]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_btnSubTitleLabel
                                                     attribute:NSLayoutAttributeLeft
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:_btnTitleLabel
                                                     attribute:NSLayoutAttributeLeft
                                                    multiplier:1
                                                      constant:0]];
    // 设置虚线的约束
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_dottedLine
                                                     attribute:NSLayoutAttributeTop
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:_btnSubTitleLabel
                                                     attribute:NSLayoutAttributeBottom
                                                    multiplier:1
                                                      constant:8]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_dottedLine
                                                     attribute:NSLayoutAttributeLeft
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:self
                                                     attribute:NSLayoutAttributeLeft
                                                    multiplier:1
                                                      constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_dottedLine
                                                     attribute:NSLayoutAttributeRight
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:self
                                                     attribute:NSLayoutAttributeRight
                                                    multiplier:1
                                                      constant:0]];
    // 设置seeDetail 约束
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_seeDetail
                                                     attribute:NSLayoutAttributeTop
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:_dottedLine
                                                     attribute:NSLayoutAttributeBottom
                                                    multiplier:1
                                                      constant:8]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_seeDetail
                                                     attribute:NSLayoutAttributeRight
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:self
                                                     attribute:NSLayoutAttributeRight
                                                    multiplier:1
                                                      constant:-8]];
}


@end
